package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 攻略
 */
@Getter
@Setter
public class StrategyDetail {
    public static final Integer STATE_RELEASE = 0;//发布状态
    public static final Integer STATE_NORMAL = 1;//草稿状态

    private Long id;
    //攻略标题
    private String title;
    //攻略创建时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    //攻略发布时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;
    //攻略序号
    private Integer sequence;
    //攻略的分类
    private StrategyCatalog catalog;
    //攻略的封面
    private String coverUrl;
    //攻略的状态
    private Integer state = STATE_NORMAL;

    //攻略内容
    private StrategyContent strategyContent;

    //大攻略
    private Strategy strategy;


    public String getJsonString() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("coverUrl", coverUrl);
        map.put("releaseTime", releaseTime);
        map.put("state", state);
        map.put("sequence", sequence);
        if (catalog != null) {
            map.put("catalog", catalog.getId());
        }
        if (strategy != null) {
            map.put("strategyId", strategy.getId());
        }
        return JSONUtil.toJsonString(map);
    }

    public String getStateDisplay() {
        if (state == STATE_RELEASE) {
            return "发布状态";
        } else if (state == STATE_NORMAL) {
            return "草稿状态";
        }
        return "";
    }


}